all files / test/helpers/ players.helpers.ts

100% Statements 17/17
100% Branches 0/0
100% Functions 5/5
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                                                       
 
import { Phase, Battle, Game } from '../../src/game.interfaces';
import { noOneParticipatedInBidding } from '../../src/helpers/bid.helpers';
import * as should from 'should';
import { getNextBiddingTurn } from '../../src/helpers/players.helpers';
 
describe('players helpers', () => {
    beforeEach(() => {
        this.state = {
            settings: {
                permitBombOnBarrel: true,
                maxBombs: 2,
                barrelPointsLimit: 880
            },
            phase: Phase.BIDDING_START,
            players: [{ id: 'adam', battlePoints: [] }, { id: 'pic', battlePoints: [] }, { id: 'alan', battlePoints: [] }],
            deck: [],
            stock: [],
            bid: [],
            cards: {},
            battle: null
        } as Game;
    });
 
    describe('getNextBiddingTurn', () => {
        it('returns  first registered player, for first bidding ever', () => {
            // assign
            const currentState = this.state;
            // act
            const nextBiddingTurnPlayerId = getNextBiddingTurn(currentState);
            //assert
            should(nextBiddingTurnPlayerId).be.equal('adam');
        });
        it('returns pic, for fifth bidding round', () => {
            // assign
            const currentState = this.state;
            currentState.players[0].battlePoints = [1, 2, 3, 4];
            // act
            const nextBiddingTurnPlayerId = getNextBiddingTurn(currentState);
            //assert
            should(nextBiddingTurnPlayerId).be.equal('pic');
        });
    });
});